using System;
using System.Collections.Generic;
using System.Linq;

public class PasswordGenerator
{
    public static void Main(string[] args)
    {
        // masīva garums, paroļu skaits
        int passwordCount;
        while (true)
        {
            Console.Write("Ievadiet paroļu SKAITU, kas lielāks par 4: ");
            string input = Console.ReadLine();
            if (int.TryParse(input, out passwordCount) && passwordCount >= 5)
            {
                break;
            }
            else
            {
                Console.WriteLine("Nederīga ievade. Lūdzu, ievadiet skaitli, kas ir lielāks par 4.");
            }
        }

        // garākās paroles simbola skaits
        int maxLength;
        while (true)
        {
            Console.Write("Ievadiet GARĀKO paroles simbolu skaitu, kas lielāks par 9: ");
            string input = Console.ReadLine();
            if (int.TryParse(input, out maxLength) && maxLength >= 9)
            {
                break;
            }
            else
            {
                Console.WriteLine("Nederīga ievade. Lūdzu, ievadiet skaitli, kas ir lielāks par 9.");
            }
        }

        // vai vajag Lielos burtus?
        bool includeUppercase;
        Console.Write("Vajag Lielos burtus simboliem (y/n): ");
        includeUppercase = Console.ReadLine().ToLower() == "y";

        // vai vajag ciparus un simbolus?
        bool includeSymbolsAndNumbers;
        Console.Write("Vajag ciparus un simbolus simboliem (y/n): ");
        includeSymbolsAndNumbers = Console.ReadLine().ToLower() == "y";

        // paroļu masīvs
        string[] passwords = new string[passwordCount];
        Random random = new Random();

        string lowerCaseChars = "abcdefghijklmnopqrstuvwxyz";
        string upperCaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string numberChars = "0123456789";
        string symbolChars = "!@#$%^&*()_+-=[]{}|;:,.<>?";

        // ģenerē paroles
        for (int i = 0; i < passwordCount; i++)
        {
            // katras paroles garums ir nejaušs, bet ne mazāks par 1 un ne lielāks par maxLength
            int currentPasswordLength = random.Next(1, maxLength + 1);
            string generatedPassword = "";

            for (int j = 0; j < currentPasswordLength; j++)
            {
                string charSet = lowerCaseChars; // sākumā mazie burti

                // pievieno lielos burtus, simbolus un ciparus, ja nepieciešams
                if (includeUppercase && random.Next(0, 3) == 0) 
                {
                    charSet += upperCaseChars;
                }
                if (includeSymbolsAndNumbers && random.Next(0, 3) == 0) 
                {
                    charSet += numberChars + symbolChars;
                }

                generatedPassword += charSet[random.Next(charSet.Length)];
            }
            passwords[i] = generatedPassword;
        }

        Console.WriteLine("\nĢenerētās paroles:");

        // izvadīt masīva vērtības
        int counter = 1;
        foreach (string password in passwords)
        {
            Console.WriteLine($"{counter}. parole: {password}");
            counter++;
        }
    }
}
